/**
 * 
 */
package com.gamutsoft.amb.common.util;

import java.util.List;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.log4j.Logger;

/**
 * @author leo.zhu
 * 
 */
public class ConfigurationUtil {
	/**
	 * Logger for this class
	 */
	private static final Logger log = Logger.getLogger(ConfigurationUtil.class);

	private static XMLConfiguration instance = null;

	// 私用构建 weiyuan
	private ConfigurationUtil() {

	}

	/** 自动初始化，避免冲突 */
	static {
		if (instance == null) {
			try {
				instance = new XMLConfiguration("configuration.xml");
			} catch (ConfigurationException e) {
				e.printStackTrace();
				log.error(e.getMessage(), e);
			}
		}
	}

	/**
	 * @return the instance
	 */
	public static XMLConfiguration getInstance() {
		return instance;
	}

	/**
	 * You can find the value through the XPATH
	 * 
	 * <pre>
	 * 		<config>
	 * 			<system>
	 * 				<name id="SO">Smart Org.</name>
	 * 			</system>
	 * 		<ftp></ftp>
	 * 		<webservice></webservice>
	 * </config>
	 * 
	 * <pre>
	 * If you want to get name of the system, for example:
	 * ConfigurationUtil.getString("system.name");
	 * 
	 * For more, if you want to get the ID of the system,you can get it like this:
	 * ConfigurationUtil.getString("system.name[@id]");
	 * 
	 * 
	 * @param xPathName
	 * @return
	 */
	public static String getString(String xPathName) {
		return instance.getString(xPathName);
	}

	/**
	 * You can find the value through the XPATH
	 * 
	 * <pre>
	 * 		<config>
	 * 			<system>
	 * 				<name id="SO">Smart Org.</name>
	 * 			</system>
	 * 		<ftp>
	 * 			<ip>127.0.0.1</ip>
	 * 			<port id="80">80</port>
	 * 		</ftp>
	 * 		<webservice></webservice>
	 * </config>
	 * 
	 * <pre>
	 * If you want to get name of the system, for example:
	 * ConfigurationUtil.getDouble("ftp.ip");
	 * 
	 * For more, if you want to get the ID of the system,you can get it like this:
	 * ConfigurationUtil.getDouble("ftp.port[@id]");
	 * 
	 * 
	 * @param xPathName
	 * @return
	 */
	public static Double getDouble(String xPathName) {
		return instance.getDouble(xPathName);
	}

	/**
	 * You can find the value through the XPATH
	 * 
	 * <pre>
	 * 		<config>
	 * 			<system>
	 * 				<name id="SO">Smart Org.</name>
	 * 			</system>
	 * 		<ftp>
	 * 			<ip>127.0.0.1</ip>
	 * 			<port id="80">80</port>
	 * 		</ftp>
	 * 		<webservice>
	 * 			<sid>1</sid>
	 * 		</webservice>
	 * </config>
	 * 
	 * <pre>
	 * If you want to get name of the system, for example:
	 * ConfigurationUtil.getDouble("ftp.ip");
	 * 
	 * For more, if you want to get the ID of the system,you can get it like this:
	 * ConfigurationUtil.getDouble("ftp.port[@id]");
	 * 
	 * 
	 * @param xPathName
	 * @return
	 */
	public static short getShort(String xPathName) {

		return instance.getShort(xPathName);
	}

	public static List getList(String xPathName){
		return instance.getList(xPathName);
	}
}
